package com.xmlreader; 
import javax.xml.parsers.*;
import java.io.*;
import java.util.ArrayList;

import org.w3c.dom.*;

import org.xml.sax.SAXException;



public class TokenReader {
	
	 public static ArrayList<String> readXML(String xmlFilePath){
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         DocumentBuilder db = null;
         try {
                 db = dbf.newDocumentBuilder();
         } catch (ParserConfigurationException pce) {
                 System.err.println(pce);
         }
         Document doc = null;
         try {
                
                 doc = db.parse(new File(xmlFilePath));
         } catch (SAXException se) {
                 System.err.println(se.getMessage());
         } catch (IOException ioe) {
                 System.err.println(ioe);
         } catch (IllegalArgumentException iae) {
                 System.out.println("Error class" + iae.getClass());
                 System.err.println(iae);
         }

         Node node = doc.getDocumentElement();
         
         NodeList nodelist = ((Element)node).getElementsByTagName("token");
         ArrayList<String> tokenList = new ArrayList<String>();
         
         int i = nodelist.getLength();
           
         for(int j=0; j<i; j++){
                Element child = (Element)nodelist.item(j);
                tokenList.add(child.getFirstChild().getNodeValue());
                //System.out.println(child.getFirstChild().getNodeValue());                
         }
         return tokenList;
 }

}
